package com.hejjon.syyapi.service.impl;

import com.hejjon.syyapi.dao.IXUserDao;
import com.hejjon.syyapi.entity.XUser;
import com.hejjon.syyapi.service.IUserService;
import com.kern.framework.bean.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by caoshi at 21:49 2021-09-16
 */
@Service
public class XUserServiceImpl implements IUserService {

    @Autowired
    private IXUserDao userDao;

    @Override
    public ResponseResult login(XUser user) {
        XUser dbUser = userDao.findByUnameAndPwd(user.getUsername(), user.getPassword());
        if (dbUser == null) {
            return new ResponseResult(-1, "error", "用户或密码不正确", null);
        }

        return new ResponseResult(0, "success", "登录成功", dbUser);
    }

    @Override
    public ResponseResult saveOrUpdate(XUser user) {
        XUser u = userDao.saveAndFlush(user);
        return new ResponseResult(0, "", "", u);
    }
}
